package kr.hyunist.androidcomplete01saeildamil.ch12;

import java.util.*;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.content.*;
import android.view.*;
import android.widget.*;

public class AlarmAdapter extends BaseAdapter {
	ArrayList<AlarmInfo> mArray;
	Context mContext;
	LayoutInflater inflater;
	
	AlarmAdapter(Context context, ArrayList<AlarmInfo> arList) {
		mContext = context;
		mArray = arList;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		return mArray.size();
	}

	@Override
	public Object getItem(int position) {
		return mArray.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){
			convertView = inflater.inflate(R.layout.customadapterex2contents, parent, false);
		}
		
		convertView.setBackgroundResource(mArray.get(position).getBackground());
		
		TextView time = (TextView) convertView.findViewById(R.id.weathercustomadaptertimetv);
		time.setText(mArray.get(position).getTime());
		
		Button btn = (Button) convertView.findViewById(R.id.weathercustomadaptertbtn);
		if(mArray.get(position).isEnable()){
			btn.setBackgroundResource(R.drawable.clark_green);
		} else {
			btn.setBackgroundResource(R.drawable.clark_gray);
		}
		
		return convertView;
	}

}
